﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using TileEngine;

namespace CarlosMisfortune.view
{
    public static class DebugView
    {
        private static Texture2D m_pixelTexture;
        private static Dictionary<String, Rectangle> m_collisionRectangles = new Dictionary<String, Rectangle>();

        public static Texture2D PixelTexture
        {
            get { return m_pixelTexture; }
            set { m_pixelTexture = value; }
        }

        public static Dictionary<String, Rectangle> CollisionRectangles
        {
            get { return m_collisionRectangles; }
            set { m_collisionRectangles = value; }
        }

        public static void Update(string a_name, Rectangle a_rect)
        {
            if (!m_collisionRectangles.ContainsKey(a_name))
            {
                m_collisionRectangles.Add(a_name, a_rect);            
            }
            else
            {
                m_collisionRectangles[a_name] = a_rect;
            }
        }

        public static void Draw(SpriteBatch a_spriteBatch)
        {
            if (m_collisionRectangles.Count > 0)
	        {
                int borderWidth = 2;
                Rectangle rect;

                for (int i = 0; i < m_collisionRectangles.Count; i++ )
                {
                    rect = m_collisionRectangles.Values.ElementAt(i);
                    rect = Camera.WorldToScreen(rect);

                    a_spriteBatch.Draw(m_pixelTexture, new Rectangle(rect.Left, rect.Top, borderWidth, rect.Height), Color.Red);
                    a_spriteBatch.Draw(m_pixelTexture, new Rectangle(rect.Right, rect.Top, borderWidth, rect.Height), Color.Red);
                    a_spriteBatch.Draw(m_pixelTexture, new Rectangle(rect.Left, rect.Top, rect.Width, borderWidth), Color.Red);
                    a_spriteBatch.Draw(m_pixelTexture, new Rectangle(rect.Left, rect.Bottom, rect.Width, borderWidth), Color.Red);
                }
	        }                        
        }
    }
}
